﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>人员-部门列表</title>
 <script type="text/javascript" src="../WF/Scripts/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="../WF/Scripts/jquery/jquery.easyui.min.js"></script>
    <script src="../WF/Scripts/QueryString.js" type="text/javascript"></script>
    <!-- 引入新版本的类库. -->
    <script src="../WF/Scripts/config.js" type="text/javascript"></script>
    <script src="../WF/Comm/Gener.js" type="text/javascript"></script>
    <script type="text/javascript">

        $(function () {

            $("#Msg").html("正在加载请稍候...");

            var empNo = GetQueryString("FK_Emp");
            var deptNo = GetQueryString("FK_Dept");

            var emp = new Entity("BP.Port.Emp", empNo);

            //该人员在当前部门下的所有岗位集合.
            var ens = new Entities("BP.GPM.DeptEmpStations");
            ens.Retrieve("FK_Emp", empNo, "FK_Dept", deptNo);

            //所有的岗位类别.
            var stationTypes = new Entities("BP.GPM.StationTypes");
            stationTypes.RetrieveAll();

            //所有的岗位s
            var stations = new Entities("BP.GPM.Stations");
            stations.RetrieveAll();


            var html = "<table border=0 style='width:100%;'>";
            html += "<caption >姓名:" + emp.Name + ", <a href='javascript:Back()'>返回</a></caption>";

            for (var i = 0; i < stationTypes.length; i++) {

                //输出类别.
                var type = stationTypes[i];
                html += "<tr>";
                html += "<th colspan=4>" + type.Name + "</th>";
                html += "</tr>";

                //输出岗位.
                var ii = -1;
                for (var idx = 0; idx < stations.length; idx++) {

                    var sta = stations[idx];
                    if (sta.FK_StationType != type.No)
                        continue;

                    ii++;

                    if (ii == 0)
                        html += "<tr>";

                    //是否存在？
                    var isHave = false;
                    for (var ddd = 0; ddd < ens.length; ddd++) {

                        var myEn = ens[ddd];
                        if (myEn.FK_Station == sta.No) {
                            isHave = true;
                            break;
                        }
                    }



                    if (isHave==true)
                        html += "<td ><label><input type=checkbox checked=checked onclick=\"javascript:Set('" + sta.No + "')\" id='" + sta.No + "'  ><font color=green>" + sta.Name + "</font></label></td>";
                    else
                        html += "<td ><label><input type=checkbox onclick=\"javascript:Set('" + sta.No + "')\" id='" + sta.No + "'  >" + sta.Name + "</label></td>";



                    if (ii == 3) {
                        ii = -1;
                        html += "</tr>";
                    }
                }
            }

            html += "</table>";

            $("#Msg").html(html);

        });

        //保存
        function Set(staNo) {

            var empNo = GetQueryString("FK_Emp");
            var deptNo = GetQueryString("FK_Dept");

            //该人员在当前部门下的所有岗位集合.
            var ens = new Entities("BP.GPM.DeptEmpStations");
            ens.Retrieve("FK_Emp", empNo, "FK_Dept", deptNo, "FK_Station", staNo);

            var en = new Entity("BP.GPM.DeptEmpStation");

            if (ens.length == 0) {
                en.FK_Dept = deptNo;
                en.FK_Emp = empNo;
                en.FK_Station = staNo;
                en.Insert();
                return;
            }

            var mypk = deptNo + '_' + empNo + '_' + staNo;
            en.SetPKVal(mypk);
            en.Delete();
        }

        function Back() {

            var empNo = GetQueryString("FK_Emp");
            var url = "EmpDepts.htm?FK_Emp=" + empNo;
            window.location.href = url;
        }

        function Del(mypk) {

            if (window.confirm('您确定要删除吗？') == false)
                return;

            var dept = new Entity("BP.GPM.DeptEmp", mypk);
            dept.Delete();

            window.location.href = window.location.href;
        }
    </script>

    <link href="../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />

</head>
<body>


<div id="Msg"></div>

</body>
</html>
